<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="Pojo.Journalism" %>
<%@ page import="Pojo.NewInfo" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>首页</title>
    <meta name="viewport" content="width=device-width,initical-scale=1.0"/>
    <link rel="stylesheet" href="./css/bootstrap.css"/>
    <link rel="stylesheet" href="./css/htgl.css"/>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#userload").click(function () {
                $.post("NewInfo");
            })
            $("#newload").click(function () {
                $.post("NewInfo");
            })
        }) 
    </script>
</head>
<body>
<nav class="navbar head" role="navigation" id="nav">
    <div class="col-md-1"></div>
    <div class="col-md-10">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand logo" href="#">后台管理</a>
                <button class="navbar-toggle aa" data-toggle="collapse" data-target="#navbar">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>
            <div class="collapse navbar-collapse" id="navbar">
                <ul class="nav navbar-nav">
                    <li class="active"><a href="index.jsp"><i class="glyphicon glyphicon-home"></i>后台首页</a></li>
                    <li><a href="用户管理.jsp" id="userload"><i class="glyphicon glyphicon-user"></i>用户管理</a></li>
                    <li><a href="infomanager.jsp" id="newload"><i class="glyphicon glyphicon-list-alt"></i>内容管理</a></li>
                    <li><a href="body.jsp"><i class="glyphicon glyphicon-list-alt"></i>前台首页</a></li>
                </ul>
                <ul class="navbar-nav nav navbar-right">
                    <li class="dropdown">
                        <a href="" class="dropdown-toggle" data-toggle="dropdown">
                            <%=request.getSession().getAttribute("username")%><span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a href=""><i class="glyphicon glyphicon-cog"></i>个人主页</a></li>
                            <li><a href=""><i class="glyphicon glyphicon-screenshot"></i>个人设置</a></li>
                            <li><a href=""><i class="glyphicon glyphicon-credit-card"></i>账户中心</a></li>
                            <li><a href=""><i class="glyphicon glyphicon-heart"></i>我的收藏</a></li>
                        </ul>
                    </li>
                    <li><a href="Cancellation.jsp"><i class="glyphicon glyphicon-off"></i>退出</a></li>
                </ul>

            </div>
        </div>
    </div>
    <div class="col-md-1"></div>
</nav>

<div class="main">
    <div class="col-md-1"></div>
    <div class="col-md-10">
        <!--前俩个表格-->
        <%Journalism j = (Journalism) request.getSession().getAttribute("journalism");%>
        <div class="col-md-6" style="width: 100%;">
            <table class="table table01 ">
                <caption>网站数据统计表</caption>
                <thead>
                <tr>
                    <th class="th">统计项目</th>
                    <th class="th">总数</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td class="th">管理员</td>
                    <td><%=j.getUsernum()%>
                    </td>
                </tr>
                <tr>
                    <td class="th">新闻</td>
                    <td><%=j.getNewnum()%>
                    </td>
                </tr>
                <tr>
                    <td class="th">标签</td>
                    <td><%=j.getTagnum()%>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>

        <!--第3行的表格-->
        <%
            List<NewInfo> list = (List<NewInfo>) request.getSession().getAttribute("newInfo");
        %>
        <div class="col-md-12 ">
            <div class="col-md-6" style="width: 100%;padding: 0px;">
                <table class="table table02">
                    <caption>新闻列表</caption>
                    <tbody>
                    <c:forEach items="${newInfo}" varStatus="i" var="li">
                        <tr>
                            <td><a href="news.jsp?id=${li.id}" class="text-left"><i
                                    class="glyphicon glyphicon-list-alt"></i>
                                    ${li.title}
                            </a>
                            </td>
                            <td class="text-right time">${li.time}
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <ul>
                    <%
                        double x = j.getNewnum();
                        int n = (int) Math.ceil(x / 10);
                        int nn = (int) request.getSession().getAttribute("index");
                        int m = nn / 10 + 1;
                    %>
                    <li>共<%=n%>页 当前第<%=m%>页</li>
                </ul>
                <ul class='pagination  fenye' id='page'>
                    <li>
                        <button id="up">上一页</button>
                    </li>
                    <li>
                        <button id="up1">&laquo;</button>
                    </li>
                    <%

                        int i = 0;
                        for (i = 1; i <= n; i++) {
//                            out.println(x/10);
                    %>
                    <li>
                        <button class="jump" value="<%=i%>"><%=i%>
                        </button>
                    </li>
                    <%
                        }
                    %>
                    <li>
                        <button id="down">&raquo;</button>
                    </li>
                    <li>
                        <button id="down1">下一页</button>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <div class="col-md-1"></div>
</div>


<script type="text/javascript" src="./js/jquery.js"></script>
<script type="text/javascript" src="./js/bootstrap.js"></script>
</body>
<script type="text/javascript">
    $(document).ready(function () {
        $(".jump").click(function () {
            var jump = $(this).val();
            $.get("Limit", {jump: jump,}, function (data) {
                if (data == 1) {
                    window.location.href = "http://localhost:8080/xinwen_war/index.jsp";
                }
            });
        })
        $("#up").click(function () {
            var what = "up";
            $.post("Limit", {what: what,}, function (data) {
                if (data == 1) {
                    alert("当前已经是第一页");
                } else {
                    window.location.href = "http://localhost:8080/xinwen_war/index.jsp";
                }
            });
        })
        $("#up1").click(function () {
            var what = "up";
            $.post("Limit", {what: what,}, function (data) {
                if (data == 1) {
                    alert("当前已经是第一页");
                } else {
                    window.location.href = "http://localhost:8080/xinwen_war/index.jsp";
                }
            });
        })
        $("#down").click(function () {
            var what = "down";
            $.post("Limit", {what: what,}, function (data) {
                if (data == 1) {
                    alert("当前是最后一页");
                } else {
                    window.location.href = "http://localhost:8080/xinwen_war/index.jsp";
                }
            });
        })
        $("#down1").click(function () {
            var what = "down";
            $.post("Limit", {what: what,}, function (data) {
                if (data == 1) {
                    alert("当前是最后一页");
                } else {
                    window.location.href = "http://localhost:8080/xinwen_war/index.jsp";
                }
            });
        })
    })
</script>
</html>
